/**
 * Posts a request to the page for section of the same page
 * @param {String} sQualifiedName ID of UpdatePanel element
 * @param {Array} controlIDs Array of element ID's whos 'click' event will update the panel
 * @param {String} sAttachIndicatorToElementId ID of element to attach load indicator to
 */
var AutoUpdatePanel = Class.create({
	/**
	 * Initializes the Update Panel
	 * 
	 * @param {String} sQualifiedName The ID of the panel to update
	 * @param {Integer} iSeconds[optional] The interval between Auto-Update requests
	 */
	initialize: function(sQualifiedName, iSeconds) {
		// Map it back to the server control (Control.UniqueID)
		this.panelName = sQualifiedName;
		// Associate with an element
		this.panelID = sQualifiedName.replace(/\$/,'_');
		// Initialize Auto-Updating
		this.commenceAutoUpdate(iSeconds);
	},
	
	/**
	 * Starts the timer which calls the Auto-Update Requests
	 * 
	 * @param {Integer} iSeconds[optional] The interval between Auto-Update requests
	 */
	commenceAutoUpdate: function(iSeconds) {
		// Set update interval if passed
		if (typeof iSeconds != "undefined") {
			this.setIntervalIncrement(iSeconds);
		}
		// If an interval is specified, begin update requests
		if (this.updateInterval) {
			this.intervalId = setInterval(this.update.bind(this), this.updateInterval);
			this.update();
		}
	},
	
	/**
	 * Stops the request timer
	 */
	ceaseAutoUpdate: function() {
		if (this.intervalId) {
			clearInterval(this.intervalId);
		}
	},
	
	/**
	 * Sets the number of seconds between Update requests
	 * 
	 * @param {Integer} iSeconds[optional] The interval between Auto-Update requests
	 */
	setIntervalIncrement: function(iSeconds) {
		this.updateInterval = iSeconds * 1000;
	},

	/**
	 * Requests updated content from the server
	 */
	update: function() {
		Page.post({target: this.panelName});
	},
	
	__Click: function(e) {
		var e = e || window.event;
		Event.stop(e);
		var arguments = $A(arguments)
		arguments.shift();
		this.update.apply(this, arguments);
	}
});